<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('农场管理列表')" />
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>选择用户：</label>
                                <select type="text" class="form-control" id="farmUid" name="farmUid">
                                    <option value="">所有</option>
                                </select>
                            </li>
                            <li>
                                <label>农场名称：</label>
                                <input type="text" name="farmName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="farmState" th:with="type=${@dict.getType('farm_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>农场规模：</label>
                                <select name="farmScale" th:with="type=${@dict.getType('farm_scale')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>地址标签：</label>
                                <input type="text" name="farmHostLable"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="farmWorkPhone"/>
                            </li>
                            <li>
                                <a class="btn btn-primary  btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning  btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wechat:WxFarm:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="wechat:WxFarm:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js"/>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wechat:WxFarm:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wechat:WxFarm:remove')}]];
        var farmStateDatas = [[${@dict.getType('farm_state')}]];
        var farmScaleDatas = [[${@dict.getType('farm_scale')}]];
        var prefix = ctx + "wechat/WxFarm";

        $(function() {
            var options = {
                url: prefix + "/list",
                detailUrl: prefix + "/detail/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "农场管理",
                columns: [
                {
                    field: 'farmId',
                    title: '编号',
                    visible: false,
                    sortable: false
                },
                    {
                        field: 'farmName',
                        title: '农场名称',
                        sortable: false
                    },
                {
                    field: 'farmUid',
                    title: '绑定用户',
                    sortable: false,
                    formatter: function(value, row, index) {
                        return "用户昵称:"+row.userName+"(ID："+value+")";
                    }
                },

                {
                    field: 'farmState',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(farmStateDatas, value);
                    }
                },
                {
                    field: 'farmScale',
                    title: '农场规模',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(farmScaleDatas, value);
                    }
                },
                {
                    field: 'farmHostLable',
                    title: '地址标签',
                    sortable: false
                },
                {
                    field: 'farmHost',
                    title: '详细地址',
                    sortable: false,
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'farmWorkName',
                    title: '联系人',
                    sortable: false
                },
                {
                    field: 'farmWorkPhone',
                    title: '联系电话',
                    sortable: false
                },
                {
                    field: 'farmTime',
                    title: '创建信息',
                    sortable: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.farmId + '\')">编辑</a> ');
                        actions.push('<a class="btn btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.farmId + '\')">删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        $.operate.ajaxGet(ctx + "/wechat/user/listAjax", function (result) {
            if(result.data.length==0){
                $.modal.alertError("暂无用户")
            }
            var html = "";
            for (var i = 0; i < result.data.length; i++) {
                html += "<option value='" + result.data[i].userId + "'>" + result.data[i].userName + "</option>";
            }
            $("#farmUid").append(html);
        })
    </script>
</body>
</html>
